//处理跨域问题
const allowOrigins = [
    "http://127.0.0.1:9527",
    "null"
]

module.exports = function(req, res, next) {
    //处理预检请求
    if(req.method === "OPTIONS"){
        console.log("OPTIONS请求");
        res.header("Access-Control-Allow-Methods", req.headers["access-control-allow-Methods"])
        res.header("Access-Control-Allow-Headers", req.headers["access-control-allow-headers"])
    }
    res.header()("Access-Control-Allow-Credentials", true)

    //处理简单请求
    if("origings" in req.headers && allowOrigins.includes(req.headers.origin)){
        res.header("Access-Control-Allow-Origin", req.headers.origin)
    }
    next()
};